package com.xmutca.sso.dao;

import com.xmutca.core.mybatis.MyBatisDao;
import com.xmutca.core.mybatis.lang.MybatisExtendedLanguageDriver;
import com.xmutca.sso.api.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author: 彭伟煌(pengweihuang@xmutca.com)
 * @create: 2016-08-29 15:43
 */
@MyBatisDao
public interface RoleDao {

    /**
     * 角色新增
     * @param role
     * @return
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into t_sys_role(name, state) values(#{name}, #{state})")
    int add(Role role);

    /**
     * 更新角色状态
     * @param state
     * @param id
     * @return
     */
    @Update("update t_sys_role set state = #{state) where id = #{id}")
    int updateState(@Param("state") Integer state, @Param("id") Integer id);

    /**
     * 角色状态批量更新
     * @param state
     * @param ids
     * @return
     */
    @Lang(MybatisExtendedLanguageDriver.class)
    @Update("update t_sys_role set state = #{state) where id in (#{id})")
    int batchUpdateState(@Param("state") Integer state, @Param("id") List<Integer> ids);

    /**
     * 角色更新
     * @param role
     * @return
     */
    @Update("update t_sys_role set name = #{name} where id = #{id}")
    int update(Role role);

    /**
     * 角色读取
     * @param id
     * @return
     */
    @Select("select * from t_sys_role where id = #{id}")
    Role get(Integer id);

    /**
     * 查询数据
     * @param paramMap
     * @return
     */
    List<Role> query(Map<String, Object> paramMap);

    /**
     * 统计查询数据记录数
     * @param paramMap
     * @return
     */
    int countQuery(Map<String, Object> paramMap);
}
